<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        //字面量是对象
        var son={
            name:'lujielong',
            age:20,
            say:function(){
                console.log('hello word!');
            }
        }
        console.log(son.say());

        //2.工厂方式
        function createObjectFactory()
        {
            var o=new Object()
            o.username='wuque'
            o.age=10
            return o;
        }
        var p11=createObjectFactory()  //对象创建工厂
        var p12=createObjectFactory()
        p11.username='biden'
        console.log('p11==>',p11.username);
        console.log('p12==>',p12.username);

        //构造函数，首字母大写，函数名和类名一样
        function People(name,age)
        {
            this.name=name
            this.age=age
            this.say=function()
            {
                console.log('hello word!');
            }
        }
        //通过构造函数创建对象
        var p1=new People('lu',20)
        var p2=new People('long',21)
        console.log(p1);

    </script>
    
</body>
</html>